/**
 * Created by xxf on 2018/2/7
 */
import React, { PureComponent } from 'react';
import moment from 'moment';
import {Link} from 'dva/router';
import { Table,Switch,Icon, Alert, Badge,Button } from 'antd';
import styles from './index.less';
import {powerControl} from '../../../utils/powerControl';
const AuthButton = powerControl(Button);

export default class DistributorManageTable extends PureComponent {

    handleTableChange=(pagination)=>{
        this.props.handleTableChange(pagination);
    }

    handleEdit=(record)=>{
        this.props.handleEdit(record);
    }

    handleDetail=(record)=>{
      this.props.handleDetail(record);
    }

    render() {
        const { data: { list, pagination },loading} = this.props;
        const columns = [
            {
                title: '真实姓名',
                dataIndex: 'user_name',
            },
            {
                title: '店铺名称',
                dataIndex: 'shop_name',
            },
            {
                title: '分销商电话',
                dataIndex: 'phone',
            },
            {
                title: '成为分销商时间',
                dataIndex: 'check_time',
            },
            {
                title: '在售商品数',
                dataIndex: 'in_seller',

            },
            {
                title: '待销售商品数',
                dataIndex: 'no_in_seller',
            },
            {
                title:'是否生效',
                dataIndex:'is_validated',
                render(val) {
                    return <Switch checkedChildren={<Icon type="check"/>} unCheckedChildren={<Icon type="cross"/>}
                                   defaultChecked={val} checked={val}/>;
                },
            },{
                title: '操作',
                fixed:'right',
                width:300,
                render: (text,record) => (
                    <p>
                        <AuthButton auth="distributorManageCh.edit" ghost  className={styles.btn} onClick={()=>this.handleEdit(record)}>编辑</AuthButton>
                        <span className={styles.splitLine}/>
                        <AuthButton auth="distributorManageCh.shopEdit" ghost  className={styles.btn} onClick={()=>this.handleDetail(record)}>店铺详情</AuthButton>
                        <span className={styles.splitLine}/>
                        <Link to={{pathname:'/distributorManage/shopAddGoods',state:record.shop_id,returnPath:'/distributorManage/distributorManages'}}>
                            <AuthButton auth="distributorManageCh.shopDetail" ghost  className={styles.btn}>商品管理</AuthButton>
                        </Link>
                    </p>
                ),
            },
        ];

        const paginationProps = {
            showSizeChanger: true,
            showQuickJumper: true,
            ...pagination,
        };

        return (
            <div className={styles.standardTable}>
                <Table
                    loading={loading}
                    rowKey={record => record.user_id}
                    dataSource={list}
                    columns={columns}
                    pagination={paginationProps}
                    onChange={(pagination)=>this.handleTableChange(pagination)}
                    scroll={{x:1500}}
                />
            </div>
        );
    }
}